/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

// DlgSplash.cpp : implementation file

#include "stdafx.h"
#include "CHScanner.h"
#include "DlgSplash.h"
#include ".\dlgsplash.h"

//---------------------------------------------------------------------------

IMPLEMENT_DYNAMIC(DlgSplash, CDialog)
DlgSplash::DlgSplash(CWnd* pParent /*=NULL*/) : CDialog(DlgSplash::IDD, pParent)
{
}

DlgSplash::~DlgSplash()
{
}

//---------------------------------------------------------------------------

void DlgSplash::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STA_PICT, staPict);
	DDX_Control(pDX, IDC_STA_MSG, staMsg);
}

//---------------------------------------------------------------------------

BEGIN_MESSAGE_MAP(DlgSplash, CDialog)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_SIZE()
END_MESSAGE_MAP()

//---------------------------------------------------------------------------

void DlgSplash::OnOK()
{
	// CDialog::OnOK();
}

void DlgSplash::OnCancel()
{
	// CDialog::OnCancel();
}

BOOL DlgSplash::OnInitDialog()
{
	CDialog::OnInitDialog();

	staMsg.textColor = RGB(0x66, 0x99, 0xFF);
	staMsg.changeTextColor = true;

	bmp.LoadBitmap(IDB_BMP_START);
	staPict.SetBitmap(bmp);

	// TODO:  Add extra initialization here

	return TRUE;  // return TRUE unless you set the focus to a control
}

//---------------------------------------------------------------------------

void DlgSplash::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// Do not call CDialog::OnPaint() for painting messages


}

//---------------------------------------------------------------------------

void DlgSplash::SetText(CString strIn)
{
	staMsg.SetWindowText(strIn);
	RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ERASENOW | RDW_UPDATENOW);
}

//---------------------------------------------------------------------------

BOOL DlgSplash::OnEraseBkgnd(CDC* pDC)
{
	if(pDC==NULL)
		return CDialog::OnEraseBkgnd(pDC);

	RECT rect;
	CBrush brush;

	GetWindowRect(&rect);
	brush.CreateSolidBrush(RGB(0, 0, 0));
	rect.right -= rect.left;
	rect.bottom -= rect.top;
	rect.left = 0;
	rect.top = 0;
	pDC->FillRect(&rect, &brush);
	brush.DeleteObject();

	return 0;
}

//---------------------------------------------------------------------------

void DlgSplash::OnSize(UINT nType, int cx, int cy)
{
	CDialog::OnSize(nType, cx, cy);

	RECT rect;
	int ww, hh;
	int mw, mh;
	int pw, ph;
	int mx, my;
	int dd;

	if(staMsg.m_hWnd==NULL) return;
	if(staPict.m_hWnd==NULL) return;

	GetWindowRect(&rect);
	ww = rect.right - rect.left;
	hh = rect.bottom - rect.top;

	staMsg.GetWindowRect(&rect);
	mw = rect.right - rect.left;
	mh = rect.bottom - rect.top;

	staPict.GetWindowRect(&rect);
	pw = rect.right - rect.left;
	ph = rect.bottom - rect.top;

	dd = 2;

	my = hh - (mh + dd + ph);
	my /=2;

	mx = ww - pw;
	mx /= 2;
	staPict.MoveWindow(mx, my, pw, ph, TRUE);

	mx = ww - mw;
	mx /= 2;
	staMsg.MoveWindow(mx, hh - my - mh, mw, mh, TRUE);
}
